package gamedemo.component.render;

import gamedemo.component.ComponentException;
import gamedemo.geom.Vector3f;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.opengl.SlickCallable;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.renderer.SGL;
import org.newdawn.slick.state.StateBasedGame;


public class AnimationRenderComponent extends RenderComponent {
	Animation animation;

	public AnimationRenderComponent(Animation animation) {
		this.animation = animation;
		// TODO Auto-generated constructor stub
	}
	
	public void setAnimation(Animation animation) {
		this.animation = animation;
	}
	
	public Animation getAnimation() {
		return animation;
	}
	
	@Override
	public int getHeight() {
		return animation.getHeight();
	}

	@Override
	public int getWidth() {
		return animation.getWidth();
	}

	@Override
	public void render(GameContainer gc, StateBasedGame sb, Graphics gr) {
		renderShadow();
		
		Vector3f ownerPos = owner.getPosition();
		Vector2f screenPos = ownerPos.get2DTransformation();
				
		animation.draw(screenPos.getX(), screenPos.getY());
				
	}
	
	private void renderShadow() {
		float shadowScale = 0.2f;
		float shadowHeight = getHeight() * shadowScale;
		Vector2f screenPos = owner.getPosition().get2DShadowTransformation(500, getHeight(), shadowScale);
		
		//Beskrivande variabelnamn +1
		float yPosAdjustedForImageHeight = screenPos.y + (getHeight() - shadowHeight);
		animation.draw(screenPos.x, yPosAdjustedForImageHeight, getWidth(), shadowHeight, new Color(0, 0, 0, 0.5f));

	}

	@Override
	public void update(GameContainer gc, StateBasedGame sb, int delta) {
		// TODO Auto-generated method stub
	}

	@Override
	public void init() throws ComponentException {
		// DO NOTHING		
	}	

}
